package com.jiayang.hhotel.presenter;

import com.jiayang.hhotel.bean.CanRentRoomModel;
import com.jiayang.hhotel.net.Api;
import com.jiayang.hhotel.ui.CanRentRoomActivity;

import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;

/**
 * Created by Administrator on 2017/5/17 0017.
 * 可租房逻辑类
 */

public class CanRentRoomPresenter extends XPresent<CanRentRoomActivity> {

    /**
     * 获取可租房列表
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @param page 页数
     */
    public void asyncLoad(String startDate,String endDate,int page){
        Api.getHomeSer().canRentRoom(1234567891,0,1,startDate,endDate, page)
                .compose(XApi.<CanRentRoomModel>getApiTransformer())
                .compose(XApi.<CanRentRoomModel>getScheduler())
                .compose(getV().<CanRentRoomModel>bindToLifecycle())
                .subscribe(new ApiSubscriber<CanRentRoomModel>() {

                    @Override
                    protected void onFail(NetError error) {
                        getV().sealPic(error.getType());
                    }

                    //正常工作
                    @Override
                    public void onNext(CanRentRoomModel Results) {
                        switch (Results.getState()){
                            case 9:
                                getV().setAdapter(Results.getPForcastRoomDtoList());
                                break;
                            case -1:
                                getV().sealPic(-1);
                                break;
                        }
                    }
                });
    }
}
